package webConfig

import (
	"github.com/go-martini/martini"
	"hotel_Manager_Api/model/dbModel"
	"hotel_Manager_Api/handler/foodType"
	"hotel_Manager_Api/model/dto"
	"hotel_Manager_Api/handler/foods"
	"hotel_Manager_Api/handler/order"
	"hotel_Manager_Api/handler/introduce"
	"hotel_Manager_Api/handler/tag"
	"net/http"
	"hotel_Manager_Api/handler/clientManage"
	"hotel_Manager_Api/handler"
	"github.com/martini-contrib/binding"
	"hotel_Manager_Api/handler/wechat"
	"hotel_Manager_Api/handler/scheduleManage"
)


func RouteConfig(m *martini.ClassicMartini)  {
	m.Group("/desk",func(r martini.Router){
		r.Get("/all",binding.Form(dto.PageCondition{}), handler.GetAllDesks)
		r.Post("/",binding.Bind(dbModel.Desk{}),handler.NewDesk)
		r.Put("/:id",binding.Bind(dbModel.Desk{}),handler.EditDesk)
		r.Delete("/:id",handler.DeleteDesk)
	})
	m.Group("/file", func(r martini.Router) {
		r.Get("/token",handler.GetQiniuPolicy)
	})

	m.Group("/unit", func(r martini.Router) {
		r.Get("/all",handler.GetAllUnit)
		r.Post("/",binding.Bind(dbModel.Unit{}),handler.NewOneUnit)
		r.Put("/:id",binding.Bind(dbModel.Unit{}),handler.EditOneUnit)
	})

	m.Group("/introduce", func(r martini.Router) {
		r.Get("",introduce.GetIntroduce)
		r.Put("",binding.Bind(dbModel.HotelIntroduce{}),introduce.EditIntroduce)
	})

	m.Group("/tag", func(r martini.Router) {
		r.Post("",binding.Bind(dbModel.Tag{}),tag.NewTag)
		r.Put("/:id",binding.Bind(dbModel.Tag{}),tag.EditTag)
		r.Delete("/:id",tag.DeleteTag)
		r.Get("",tag.GetAllTags)
	})

	m.Group("/foodType", func(r martini.Router) {
		r.Post("",binding.Bind(dbModel.FoodType{}),foodType.NewFoodType)
		r.Get("/all",foodType.GetAllFoodType)
		r.Put("/:id",binding.Bind(dbModel.FoodType{}),foodType.EditFoodType)
		r.Delete("/:id",foodType.DeleteFoodType)
		r.Put("/order/change",binding.Bind(dto.ChangeOrderDto{}),foodType.ChangeOrder)
	})

	m.Group("/food", func(r martini.Router) {
		r.Post("",binding.Bind(dbModel.Food{}),foods.NewFood)
		r.Get("/:typeId",binding.Form(dto.PageCondition{}),foods.GetFoods)
		r.Put("/disable/:id",foods.ChangeFoodStatus)
		r.Put("/:id",binding.Bind(dbModel.Food{}),foods.EditFood)
		r.Delete("/:id",foods.DeleteFood)
	})
	m.Get("/allFood",wechat.VerifyWechatUserCanOrder,foods.GetAllFoods)

	m.Group("/order", func(r martini.Router) {
		r.Get("/getAll",order.GetAllOrders)
		r.Put("/bulkChangeStatus",binding.Bind([]dto.ChangeOrderStatusDto{}),order.BulkChangeStatus)
		r.Put("/status/:id/:status",order.ChangeStatus)
		r.Delete("/:deskId",order.DinnerFinish)
	})

	m.Group("/dinner", func(r martini.Router) {
		r.Get("/:deskOrderId",order.GetOrders)
		r.Post("",wechat.VerifyWechatUserCanOrder,binding.Bind([]dbModel.Order{}),order.NewOrder)
		r.Put("/changeDesk/:deskOrderId/:dstDeskId",order.ChangeDesk)
	})

	m.Group("/wechat", func(r martini.Router) {
		r.Get("/generateQrcode/:deskId",wechat.CreateQrCode)
	})
	m.Any("/wechatapi", func(res http.ResponseWriter, req *http.Request) {
		wechat.GetWeixin().CreateHandlerFunc(res,req).ServeHTTP(res,req)
	})
	m.Group("/clients", func(r martini.Router) {
		r.Get("",binding.Form(dto.PageCondition{}),clientManage.GetClients)
	})

	m.Group("/schedule", func(r martini.Router) {
		r.Get("/desks",scheduleManage.GetAlldeskOrderSchedules)
		r.Post("",binding.Bind(scheduleManage.DeskOrderScheduleRequst{}),scheduleManage.NewSchedule)
	})
}